package com.smartstate.dataManagement.util;


import com.smartstate.dataManagement.entity.LoginUser;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Enumeration;

public class UserUtils {
    // 关于枚举值的处理
    public static String  getUserId(Enumeration e){
        String userId=null;
        while(e.hasMoreElements()){
            userId=e.nextElement().toString();
        }
        return  userId;
    }

    public static LoginUser getLoginUser() {
        //判断是否可以转换
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal instanceof LoginUser) {
            //LoginUser解加工
            LoginUser  loginUser= (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            String username=loginUser.getUsername();
            loginUser.setUsername(username.split("&")[0]);
            return loginUser;
        }
        return null;
    }

}
